#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "Timer0.h"

unsigned char Sec=55,Min=59,Hour=23;
void main()
{
	LCD_Init();
	Timer0_Init();
	LCD_ShowString(1,1,"Clock:");
	LCD_ShowString(2,1,"  :  :");
	while(1)
	{
		LCD_ShowNum(2,7,Sec,2);
		LCD_ShowNum(2,4,Min,2);
		LCD_ShowNum(2,1,Hour,2);
	}
}

void Timer0_Rountine() interrupt 1 //这个是中断号，就是相当于是你T0发生中断了，就会跳到这个地方来，interrupt 1就是T0的中断号，前面的名字是自己取的
{
	static unsigned int Timer0_count=0;
	TH0=64535/256;//重新初始化
	TL0=64535%256;
	Timer0_count++;
	if(Timer0_count>=1000)//1s
	{
		Timer0_count=0;
		Sec++;//这么刚好就是一秒进来一次，然后++
		if(Sec>=60)
		{
			Sec=0;
			Min++;
			if(Min>=60)
			{
				Min=0;
				Hour++;
				if(Hour>=24)
				{
					Hour=0;
				}
			}
		}
	}
}